package controller

import (
	"user-center/dto"
	"user-center/query"
	"user-center/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(SysDevicesController{
		sysDevicesService: service.NewSysDevicesService(),
	})
}

type SysDevicesController struct {
	sysDevicesService service.SysDevicesService
}

// 查询
// @Router [get] [/sysdevices/:id]
func (m SysDevicesController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDevicesService.Get(id)
}

// 增加
// @Router [post] [/sysdevices]
func (m SysDevicesController) Save(c *gin.Context, dto *dto.SysDevicesDTO) any {
	dto.Id = ""
	return m.sysDevicesService.Save(dto)
}

// 修改
// @Router [put] [/sysdevices/edit]
func (m SysDevicesController) UpdateById(c *gin.Context, dto *dto.SysDevicesDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDevicesService.UpdateById(dto)

}

// 删除
// @Router [delete] [/sysdevices/:id]
func (m SysDevicesController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDevicesService.DeleteById(id)
}

// 查询列表
// @Router [post] [/sysdevices/page]
func (m SysDevicesController) QueryPage(c *gin.Context, query *query.SysDevicesQueryDTO) any {
	return m.sysDevicesService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/sysdevices/list]
func (m SysDevicesController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.sysDevicesService.QueryList(query)
}
